/**
 * 登录相关接口
 */
import api from '@/api/request'

let domain = ''

// 发送验证码（4位） 注册
export const sendSMSCode = function (data) {
  let lang = window.localStorage.getItem('lang') || 'zh-CN'
  switch(lang){
    case 'zh-CN':
      lang = 'CN'
      break
    case 'cht':
      lang = 'CNZH'
      break
    case 'kr':
      lang = 'KO'
      break
    case 'jp':
      lang = 'JA'
      break
    case 'ar':
      lang = 'AR'
      break
    case 'de':
      lang = 'DE'
      break
    case 'es':
      lang = 'ES'
      break
    case 'fr':
      lang = 'FR'
      break
    case 'it':
      lang = 'IT'
      break
    case 'th':
      lang = 'TH'
      break
    case 'ru':
      lang = 'RU'
      break
    default:
      lang = 'EN'
  }
  data.lang = lang

  return api.post(`${domain}api/v3/user/sendSms`, {
    data,
    cancel:false
  })
}

// 发送验证码（6位）
export const sendAuthSms = function (data) {
  let lang = window.localStorage.getItem('lang') || 'zh-CN'
  switch(lang){
    case 'zh-CN':
      lang = 'CN'
      break
    case 'cht':
      lang = 'CNZH'
      break
    case 'kr':
      lang = 'KO'
      break
    case 'jp':
      lang = 'JA'
      break
    case 'ar':
      lang = 'AR'
      break
    case 'de':
      lang = 'DE'
      break
    case 'es':
      lang = 'ES'
      break
    case 'fr':
      lang = 'FR'
      break
    case 'it':
      lang = 'IT'
      break
    case 'th':
      lang = 'TH'
      break
    case 'ru':
      lang = 'RU'
      break
    default:
      lang = 'EN'
  }
  data.lang = lang

  return api.post(`${domain}api/v3/individual/sendAuthSms`, {
    data,
    cancel: false
  })
}


// 注册
export const register = function (data) {
  return api.post(`${domain}api/v2/user/register`, {
    data,
    showLoading: true
  })
}

// 登录
export const login = function (data) {
  return api.post(`${domain}api/v2/user/login`, {
    data,
    cancel: false,
    showLoading: true
  })
}

// 重置密码
export const mobileResetPwd = function (data) {
  return api.post(`${domain}api/v2/user/mobileResetPwd`, {
    data,
    cancel: false,
    showLoading: true
  })
}

// 获取用户信息
export const getUserInfo = function () {
  return api.get(`${domain}api/v2/user/info`, {
    cancel: false
  })
}
